<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script>
    // 结构两边 一样
    let [a, b, c] = [1, 2, 3];
    console.log(a, b, c);// 1,2,3
    let [aa, [bb, bc]] = [1, [2, 3]];
    console.log(aa, bb, bc); // 1,2,3
    let [ad, bd, cd = "default"] = [1, [2, 3]]; // todo 默认值
    console.log(ad, bd, cd) // 1, [2,3]

    let [ae, be] = [1, 2, 3];
    console.log(ae,be); // 1,2 最后 一个被省略

    let [af, bf,...cf] = [1, 2, 3];
    console.log(ae,be,cf); // 1,2 [3]

    let json = {
        name: "aa",
        age: 11,
    };
    let {name, age} = json; //todo  这里代表json的属性
    console.log(name, age); // aa,11

    let {name: nn, age: age1} = json; //todo  : 后面是别名
    console.log(nn, age1) // aa,11

    let {aa1, bb1, cc1} = {aa1: "aa1", bb1: "bb1"}
    console.log(aa1, bb1, cc1) // aa1 bb1 undefined.


    //todo 交换变量
    let [aa2, bb2] = [1, 2];
    [bb2, aa2] = [aa2, bb2]
    console.log(aa2, bb2) // 2,1

    function abc() {
        return [a, b]
    };

    let [aa3, bb3] = abc();
    console.log(aa3, bb3); // 1,2

    function abcd() {
        return {aa:1,bb:2}
    }

    let [aa4, bb4] = abc();
    console.log(aa4, bb4) // 1,2

</script>
<body>

</body>
</html>